/*   */
$(function () {
    // var geoCoordMap = {
    //     '经开':[123.406664,41.788074],
    //     '铁西区':[123.350664,41.787808],
    //     '于洪区':[123.310829,41.795833],
    //     '皇姑区':[123.405677,41.822336],
    //     '辽中区':[122.731269,41.512725],
    //     '新民市':[122.828868,41.996508],
    //     '大东区':[123.469956,41.808503],
    //     '和平区':[123.406664,41.788074],
    //     '沈河区':[123.445696,41.795591],
    //     '浑南区':[123.458981,41.741946],
    //     '沈北新区':[123.521471,42.052312],
    //     '苏家屯区':[123.341604,41.665904],
    //     '法库县':[123.416722,42.507045],
    //     '康平县':[123.352703,42.741533]
    // };
    map();

    function map() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('map_1'));
        var _pageData = [{area_name: '铁西区', ruku_data: 927.6, chabu_data: 3199.46},
            {area_name: '于洪区', ruku_data: 2568.74, chabu_data: 5240.54},
            {area_name: '皇姑区', ruku_data: 1727.3, chabu_data: 4962.19},
            {area_name: '经开', ruku_data: 2321.61, chabu_data: 2433.18},
            {area_name: '辽中区', ruku_data: 925.61, chabu_data: 904.95},
            {area_name: '新民市', ruku_data: 4515.1, chabu_data: 4679.1},
            {area_name: '大东区', ruku_data: 1.01, chabu_data: 101.06},
            {area_name: '和平区', ruku_data: 859.74, chabu_data: 935.55},
            {area_name: '沈河区', ruku_data: 0, chabu_data: 60.51},
            {area_name: '浑南区', ruku_data: 50, chabu_data: 150},
            {area_name: '沈北新区', ruku_data: 1.25, chabu_data: 34.61},
            {area_name: '苏家屯区', ruku_data: 0.99, chabu_data: 80.99},
            {area_name: '法库县', ruku_data: 0.15, chabu_data: 150.15},
            {area_name: '康平县', ruku_data: 0, chabu_data: 0}];
        var toolTipData = [];
        var colorData = [];
        $.each(_pageData, function (i, v) {
            var areaData = {
                'name': '',
                'value': []
            };
            var rukuValue = {
                'name': '',
                'value': 0
            };
            var chabuValue = {
                'name': '',
                'value': 0
            };
            var areaColorData = {
                'name': '',
                'value': 0
            };
            areaData.name = v.area_name;
            areaColorData.name = v.area_name;
            rukuValue.name = "入库金额";
            rukuValue.value = v.ruku_data;
            areaColorData.value = v.ruku_data;
            chabuValue.name = "查补金额";
            chabuValue.value = v.chabu_data;

            areaData.value.push(rukuValue);
            areaData.value.push(chabuValue);

            toolTipData.push(areaData);
            colorData.push(areaColorData);
        });


        option = {
            tooltip: {
                trigger: 'item',
                formatter: function (params) {
                    if (typeof (params.value)[2] == "undefined") {

                        var toolTiphtml = ''

                        for (var i = 0; i < toolTipData.length; i++) {

                            if (params.name == toolTipData[i].name) {

                                toolTiphtml += toolTipData[i].name + ':<br>'

                                for (var j = 0; j < toolTipData[i].value.length; j++) {

                                    toolTiphtml += toolTipData[i].value[j].name + ':' + toolTipData[i].value[j].value + "<br>"

                                }

                            }

                        }


                        return toolTiphtml;

                    } else {

                        var toolTiphtml = ''

                        for (var i = 0; i < toolTipData.length; i++) {

                            if (params.name == toolTipData[i].name) {

                                toolTiphtml += toolTipData[i].name + ':<br>'

                                for (var j = 0; j < toolTipData[i].value.length; j++) {

                                    toolTiphtml += toolTipData[i].value[j].name + ':' + toolTipData[i].value[j].value + "<br>"

                                }

                            }

                        }
                        return toolTiphtml;
                    }
                }
            },
            visualMap: { // 左侧小导航图标
                show: true,
                x: 'right',
                y: 'middle',
                textStyle: {
                    fontSize: 8,
                    color: "#ffefd5"
                },
                splitList: [{
                    start: 0,
                    end: 99.99
                },
                    {
                        start: 100,
                        end: 999.99
                    },
                    {
                        start: 1000,
                        end: 9999.99
                    },
                    {
                        start: 10000,
                        end: 99999.99
                    },
                    {
                        start: 100000
                    }
                ],
                color: ['#A52A2A', '#DC143C', '#E55B25', '#F2AD92', '#F9DCD1']
            },
            series: [{
                name: '入库金额',
                type: 'map',
                mapType: 'shenyang',
                roam: true, // 禁用拖动和缩放
                itemStyle: { // 图形样式
                    normal: {
                        borderWidth: .5, //区域边框宽度
                        areaColor: '#4c60ff',
                        borderColor: '#002097'
                    },
                    emphasis: { // 鼠标滑过地图高亮的相关设置
                        borderWidth: .5,
                        borderColor: '#4b0082',
                        areaColor: '#293fff'
                    }
                },
                label: { // 图形上的文本标签
                    normal: {
                        show: true, //省份名称
                        fontSize: 8,
                    },
                    emphasis: {
                        show: true,
                        fontSize: 8,
                    }
                },
                data: colorData
            }]
        };

        myChart.setOption(option);
        window.addEventListener("resize", function () {
            myChart.resize();
        });
    }

})

